package org.jeecg.eqp.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.eqp.entity.EqpSpchkdetailValue;
import org.jeecg.eqp.mapper.EqpSpchkdetailValueMapper;
import org.jeecg.eqp.service.IEqpSpchkdetailValueService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.eqp.vo.EqpSpchkdetailValueVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 点检记录详细表
 * @Author: shaolong
 * @Date: 2022-10-13
 * @Version: V1.0
 */
@Service
public class EqpSpchkdetailValueServiceImpl extends ServiceImpl<EqpSpchkdetailValueMapper, EqpSpchkdetailValue> implements IEqpSpchkdetailValueService {

    @Autowired
    private EqpSpchkdetailValueMapper eqpSpchkdetailValueMapper;

    @Override
    public List<EqpSpchkdetailValue> selectByMainId(String mainId) {
        return eqpSpchkdetailValueMapper.selectByMainId(mainId);
    }

    @Override
    public Result<String> edit(EqpSpchkdetailValue eqpSpchkdetailValue) {
        LambdaUpdateWrapper<EqpSpchkdetailValue> eq = new LambdaUpdateWrapper<EqpSpchkdetailValue>();
        eq.eq(EqpSpchkdetailValue::getRecId, eqpSpchkdetailValue.getRecId());
        boolean update = update(eqpSpchkdetailValue, eq);
        return update ? Result.ok("修改成功!") : Result.error("修改失败!");
    }

    @Override
    public IPage<EqpSpchkdetailValueVO> pageDetailList(Page<EqpSpchkdetailValueVO> page, EqpSpchkdetailValue param) {
        IPage<EqpSpchkdetailValueVO> page1 = eqpSpchkdetailValueMapper.pageDetailList(page, param);
        if (page1.getRecords().isEmpty()) {
            //生成一张单据
            IPage<EqpSpchkdetailValueVO> detailList = eqpSpchkdetailValueMapper.createDetailList(page, param);
            if (!detailList.getRecords().isEmpty()) {
                return detailList;
            }else {
                return page;
            }
        }
        return page1;
    }
}
